﻿using System;
using System.Collections.Specialized;
using System.Web.UI.WebControls;
using DBFile.Core.Web;

namespace DBFile.WebApp
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			
		}
        
        protected void UploadFileClick(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Request.SaveFilesToDB();
                RefreshList();
            }
        }

        protected void RefreshClick(object sender, EventArgs e) 
        {
            RefreshList();
        }

        private void RefreshList()
        {
            NameValueCollection col = DBFile.Core.DBFile.GetFileList("");
                      
            gvFiles.DataSource = col;
            gvFiles.DataBind();
        }

        protected void gvFiles_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int index = e.RowIndex;

            Delete(index);

            RefreshList();
        }

        private void Delete(int index)
        {
            NameValueCollection col = DBFile.Core.DBFile.GetFileList("");
            string filename = col[index];

            DBFile.Core.DBFile.Delete(filename);
        }
	}
}
